﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
//51aspx源码专家
public partial class Manage_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Random rnd = new Random();
            this.Label1.Text = rnd.Next(0, 9).ToString() + rnd.Next(0, 9).ToString() + rnd.Next(0, 9).ToString() + rnd.Next(0, 9).ToString();
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid == true)
        {
            if (this.number.Text != this.Label1.Text)
            {
                Response.Write(this.number.Text +this.Label1.Text);
                Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
            }
            else
            {
                SqlConnection strcon = Class1.DBconnection();
                strcon.Open();
                SqlCommand scd = new SqlCommand("select count(*) from tb_Admin where username='" + this.username.Text.ToString() + "' and userpwd='" + this.userpwd.Text.ToString() + "'", strcon);
                int count = Convert.ToInt32(scd.ExecuteScalar());
                if (count > 0)
                {
                    Session["adminname"] = this.username.Text.ToString();
                    Session["username"] = this.username.Text.ToString();
                    Response.Redirect("index.aspx");
                }
                else
                {
                    Response.Write("<script language=javascript>alert('您输入的用户名或者密码有误');location='javascript:history.go(-1)'</script>");
                }
            }
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string username1 = this.username.Text.ToString();
        for (int i = 0; i < (int)username1.Length; i++)
        {
            string name = username1.Substring(i, 1);
            if (name == "'" || name == "%" || name == "<" || name == ">" || name == "&" || name == "|")
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }
    }
    protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string userpwd1 = this.userpwd.Text.ToString();
        for (int i = 0; i < (int)userpwd1.Length; i++)
        {
            string pwd = userpwd1.Substring(i, 1);
            if (pwd == "'" || pwd == "%" || pwd == "<" || pwd == ">" || pwd == "&" || pwd == "|")
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }
    }
}
